package guava.listsTest;

import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: liuliwei
 * Date: 2017-06-03
 * Time: 下午1:50
 * Description: ${description}
 */
public class ListsTest {
    public static void main(String[] args) {
        try {
            System.out.println("Test1: Lists.asList 方法返回的集合不可被编辑，将抛出异常");
            Integer[] intArray={1,2,100,3,4,5};
            List<Integer> list = Lists.asList(3,intArray);
            list.add(3);
        } catch (Exception e) {
            e.printStackTrace();
        }


        System.out.println("Test2: Guava Collections2 过滤集合");
        List<Integer> integers=Lists.newArrayList();
        integers.add(3);
        integers.add(4);
        integers.add(100);
        integers.add(10);
        integers.add(110);
        integers.add(130);

        System.out.println(Collections2.filter(integers, new Predicate<Integer>() {
            public boolean apply(Integer input) {
                return input > 10;
            }
        }));
        System.out.println(integers);

        System.out.println("Test3: Guava Lists.newArrayList(E...)");
        List<Integer> integers1 = Lists.newArrayList(1, 3, 4);
        System.out.println(integers1);
    }
}
